import React from 'react';

import BaseAction from '../common/BaseAction';
import Constants from '../../common/Constants';
import ResponseConstants from '../../common/ResponseConstants';
import {ObjUtils} from '../../utils/Utils';

export default class UserRequestAPPConfigAction extends BaseAction {
  constructor(props) {
    super(props);

    this.moduleType = Constants.MODULE_TYPE.USER;
    this.name = "UserRequestAPPConfigAction";
  }

  finish(responseData, result, response) {
    let value = "";
    let configSuccess = false;
    if(result === true && responseData != null) {
      value = responseData.value;
      configSuccess = true;
    }
    else {
      value = "无此key" + this.data.key;
    }
    // let config = this.caller.state.configData.clone(); 报错
    // config[this.data.key] = value;
    let configDataDic;
    if(this.caller.state.configDataDic == undefined) {
      configDataDic = {};
    }
    else {
      configDataDic = ObjUtils.copy(this.caller.state.configDataDic);
    }
    configDataDic[this.data.key] = value;
    this.caller.setState({
      configDataDic:configDataDic,//新加的，为了兼容一个页面多个请求多情况
      configData:{key:this.data.key,value:value},//老的，为了保证老的不出问题，所以不改这个
      configValue : value,
      configSuccess:configSuccess
    })
  }
}
